package cc.sunwl.security.exception;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import cc.sunwl.security.vo.RestRusult;

@RestControllerAdvice
public class ResponseExceptionHandler {

	@ExceptionHandler(value = AccessDeniedException.class)
	@ResponseStatus(HttpStatus.FORBIDDEN)
	public RestRusult accessDeniedException(HttpServletRequest req, Exception e) {
		RestRusult result = new RestRusult();
		result.setStatus(HttpStatus.FORBIDDEN.value());
		result.setMsg(e.getMessage().toString());
		result.setObj(req.getServletPath());
		return result;
	}
}
